package br.com.kapa.beans;

import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;


@Stateless(mappedName="bean/mensagem")
public class MensagemBean implements MensagemBeanRemote{


	@Resource(mappedName = "jms/FabricaIndustriaResource")
	ConnectionFactory connectionFactory;

	@Resource(mappedName = "jms/IndustriaResource")
	Queue queue;
    
    @Override
    public void enviaMensagem(String mensagem) throws JMSException{
      
        Connection con = connectionFactory.createConnection();
        Session session = con.createSession(true, 0);
        MessageProducer mp = session.createProducer(queue);
        TextMessage msg = session.createTextMessage();
        msg.setText(mensagem);
        mp.send(msg);
        mp.close();
        session.close();
        con.close();
    }
}
